
$(document).ready(function() {

    /*
        Fullscreen background
    */
    $.backstretch('assets/img/bg.jpg');

    /*
        Contact form
    */
    $('.contact-us').submit(function(e) {

        e.preventDefault();
        $('.contact-us input, .contact-us textarea').removeAttr('style');
        $('.error').remove();

        var postdata = $('.contact-us').serialize();
        $.ajax({
            type: 'POST',
            url: 'assets/contact.php',
            data: postdata,
            dataType: 'json',
            success: function(returned_data) {

                var j = 0;
                var submit_ok = true;

                $.each(returned_data, function(key, value) {
                    if(value != '') {
                        $('.contact-us .' + key).attr('style', 'border-color: #e67632; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none;');
                        $('.contact-us .' + key).focus();
                        $('.contact-us').append('<div class="error"> ' + value + '</div>');
                        $('.error').css('top', (108 + j*60) + 'px');
                        $('.error').fadeIn('slow');
                        submit_ok = false;
                        return false;
                    }
                    j++;
                });

                if(submit_ok) {
                    $('.contact-us').append('<p style="display: none;">Thanks for contacting us! We will get back to you very soon.</p>');
                    $('.contact-us input, .contact-us textarea, .contact-us button').remove();
                    $('.contact-us p').fadeIn('slow');
                }
            }
        });
    });

});
